<?php
/**
 * WhitePaper functions and definitions
 *
 * Sets up the theme and provides some helper functions. Some helper functions
 * are used in the theme as custom template tags. Others are attached to action and
 * filter hooks in WordPress to change core functionality.
 *
 * When using a child theme (see http://codex.wordpress.org/Theme_Development and
 * http://codex.wordpress.org/Child_Themes), you can override certain functions
 * (those wrapped in a function_exists() call) by defining them first in your child theme's
 * functions.php file. The child theme's functions.php file is included before the parent
 * theme's file, so the child theme functions would be used.
 *
 * Functions that are not pluggable (not wrapped in function_exists()) are instead attached
 * to a filter or action hook. The hook can be removed by using remove_action() or
 * remove_filter() and you can attach your own function to the hook.
 *
 * For more information on hooks, actions, and filters, see http://codex.wordpress.org/Plugin_API.
 *
 * @package WordPress
 * @subpackage WhitePaper
 * @since WhitePaper 1.0
 */

/**
 * Set the content width based on the theme's design and stylesheet.
 */
 
/////////////////////////// Commentlist ////////////////////////
function mytheme_comment($comment, $args, $depth) {
   $GLOBALS['comment'] = $comment;
   $oddcomment = 'comment-item';
	global $commentcount;
	if(!$commentcount) {
		$commentcount = 0;
		}
?>
		<li class="<?php echo $oddcomment; ?>" id="comment-<?php comment_ID() ?>">
			<div class="commentmetadata clear">
				<?php echo get_avatar($comment,48); ?>
				<div class="comment-author left"><strong><?php comment_author_link() ?></strong><?php _e('Said&#58;'); ?><?php edit_comment_link('Edit Comment','',''); ?></div> <div class="comment-time right"><a href="#comment-<?php comment_ID() ?>" title=""><?php comment_date('F jS, Y') ?> <?php _e('at');?> <?php comment_time() ?></a></div>  
				<?php if ($comment->comment_approved == '0') : ?>
				<em><?php _e('Your comment is awaiting moderation.'); ?></em>
				<?php endif; ?>
			</div>
			<?php comment_text() ?>
			<div class="reply">
				<?php comment_reply_link(array_merge( $args, array('depth' => $depth,'reply_text' => 'Reply', 'max_depth' => $args['max_depth']))) ?>
			</div>
  <?php
}
function list_pings($comment, $args, $depth) {
       $GLOBALS['comment'] = $comment;
?>
<li id="comment-<?php comment_ID(); ?>">
  <?php comment_author_link(); ?>
</li>
<?php }

////////////////////////////////////////////////////////////////////////////////
// Recent Comments
////////////////////////////////////////////////////////////////////////////////
if (function_exists('mdv_recent_comments')) { 
}else{
	function mdv_recent_comments($no_comments = 10, $comment_lenth = 5, $before = '<li class="mdv_comments">', $after = '</li>', $show_pass_post = false, $comment_style = 0) {
	    global $wpdb;
	    $request = "SELECT ID, comment_ID, comment_content, comment_author, comment_author_url, post_title FROM $wpdb->comments LEFT JOIN $wpdb->posts ON $wpdb->posts.ID=$wpdb->comments.comment_post_ID WHERE post_status IN ('publish','static') ";
		if(!$show_pass_post) $request .= "AND post_password ='' ";
		$request .= "AND comment_approved = '1' ORDER BY comment_ID DESC LIMIT $no_comments";
		$comments = $wpdb->get_results($request);
	    $output = '';
		if ($comments) {
			foreach ($comments as $comment) {
				$comment_author = stripslashes($comment->comment_author);
				if ($comment_author == "")
					$comment_author = "anonymous"; 
				$comment_content = strip_tags($comment->comment_content);
				$comment_content = stripslashes($comment_content);
				$words=split(" ",$comment_content); 
				$comment_excerpt = join(" ",array_slice($words,0,$comment_lenth));
				$permalink = get_permalink($comment->ID)."#comment-".$comment->comment_ID;

				if ($comment_style == 1) {
					$post_title = stripslashes($comment->post_title);
					$url = $comment->comment_author_url;

					if (empty($url))
						$output .= $before . $comment_author . ' on ' . $post_title . '.' . $after;
					else
						$output .= $before . "<a href='$url' rel='external'>$comment_author</a>" . ' on ' . $post_title . '.' . $after;
				}
				else {
					$output .= $before . '<a href="' . $permalink . '" title="View the entire comment by ' . $comment_author . '">' . $comment_author . ': ' . $comment_excerpt . '...</a>' . $after;
				}
			}
			$output = convert_smilies($output);
		} else {
			$output .= $before . "None found" . $after;
		}
	    echo $output;
	}
}

/**
 * Display navigation to next/previous pages when applicable
 */
function whitepaper_nav( $nav_id ) {
	global $wp_query;

	if ( $wp_query->max_num_pages > 1 ) : ?>
		<nav id="<?php echo $nav_id; ?>">
			<span class="nav_pre"><?php previous_posts_link( __( '&laquo;Newer posts', 'whitepaper' ) ); ?></span>
			<span class="nav_next"><?php next_posts_link( __( 'Older posts &raquo;', 'whitepaper' ) ); ?></span>
		</nav><!-- #nav-above -->
	<?php endif;
}

if ( function_exists('register_sidebar') )

    register_sidebar();

?>
